#include <iostream>
#include <string.h>
#include <set>
using namespace std;

int v, e, k, n;
int ep = 0;
bool vis[505];
set<int> colors;//记录填色的颜色数，题目要求一定为k种

struct EDGE
{
    int s, e;
    EDGE *next;
} edges[250005];

struct NODE
{
    int color;
    EDGE *first;
} nodes[505];

void addedge(int s, int e)
{
    edges[ep].s = s;
    edges[ep].e = e;
    edges[ep].next = nodes[s].first;
    nodes[s].first = &edges[ep];
    ep++;
}

bool legal()
{
    for (int i = 0; i < v; i++)
    {
        if (!vis[i])
        {
            vis[i] = true;
            EDGE *p = nodes[i].first;
            while (p != NULL)
            {
                if (nodes[p->s].color == nodes[p->e].color)
                {
                    return false;
                }
                p = p->next;
            }
        }
    }
    return true;
}

int main()
{
    cin >> v >> e >> k;
    for (int i = 0; i < e; i++)
    {
        int s, e;
        cin >> s >> e;
        addedge(s - 1, e - 1);//-1让序号从0开始
        addedge(e - 1, s - 1);
    }
    cin >> n;
    while (n--)
    {
        set<int>().swap(colors);
        memset(vis, false, sizeof(vis));
        for (int i = 0; i < v; i++)
        {
            int color;
            cin >> color;
            colors.insert(color);
            nodes[i].color = color;
        }
        if (colors.size() == k && legal())//颜色数按定义要求一定要是k（之前没注意定义判断<=k错了测试点2）
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}